<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>客户投诉统计</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <!--ajax方式请求后台-->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <!--JQuery-->
    <script src="/crm/js/jquery-3.3.1.min.js"></script>
    <script src="/crm/js/echarts.js"></script>
    <style>
        .marginT{
            margin-left: 740px;
        }
    </style>
</head>
<body>
<div id="lxlStatShow">
    <h3 style="width: 811px;text-align: center">请选择您的搜索条件</h3>
    <el-form :model="statForm" :rules="rules" ref="statForm" label-width="100px" class="statForm"
             :inline="true">
        <el-form-item label="时间段">
            <el-date-picker
                    v-model="statForm.createtime"
                    type="datetimerange"
                    :picker-options="pickerOptions2"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    size="mini"
                    align="right">
            </el-date-picker>
        </el-form-item>
        <el-form-item label="统计方式" prop="sort">
            <el-select v-model="statForm.sort" placeholder="请选择统计方式" size="mini">
                <el-option label="按投诉类型" value="sort"></el-option>
                <el-option label="按紧急程度" value="degree"></el-option>
                <el-option label="按投诉状态" value="status"></el-option>
                <el-option label="按投诉方式" value="way"></el-option>
                <el-option label="按被投诉员工" value="userid"></el-option>
                <el-option label="按被投诉产品" value="numbers"></el-option>
            </el-select>
        </el-form-item>
    </el-form>
    <div>
        <el-row>
            <el-button class="marginT" size="small" type="primary" @click="submitStatForm('statForm')">确定</el-button>
        </el-row>
    </div>
    <div style="width: 650px;height:420px;">
        <div id="echart" style="width: 600px;height:400px;margin-left:150px;" ref="echart"></div>
    </div>
</div>
<script>
    var vm = new Vue({
        el: "#lxlStatShow",
        data: {
            statForm: {
                createtime: '',
                sort: '',
            },
        },
        created: function () {
        },
        methods: {
            //提交统计信息
            submitStatForm: function(formName){
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        vm.$nextTick(() => vm.echart()) // 点击之后立即执行this.$nextTick这个函数，dom就是更新之后的dom了，this.$refs就能获取到dom的实例了
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                })
            },
            //统计图
            echart: function() {
                // 绘制客户来源统计饼图
                var chart = echarts.init(this.$refs.echart);
                chart.clear();
                var query = {
                    "start": vm.statForm.createtime[0],
                    "end": vm.statForm.createtime[1],
                    "sort": vm.statForm.sort,
                };
                if(query.sort=="userid" || query.sort=="numbers"){
                    var url = "doStatOth";
                    axios.post(url, query).then(function (response) {
                        if(response.data.pa=="暂无统计数据"){
                            option = {
                                title: {
                                    text: '暂无统计数据',
                                    x: 'center'
                                },
                                tooltip: {
                                    trigger: 'item',
                                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                                },
                                legend: {
                                    orient: 'vertical',
                                    left: 'left',
                                    data: '',
                                },
                                series: [
                                    {
                                        name: '',
                                        type: 'pie',
                                        radius: '55%',
                                        center: ['50%', '60%'],
                                        data: '',
                                        itemStyle: {
                                            emphasis: {
                                                shadowBlur: 10,
                                                shadowOffsetX: 0,
                                                shadowColor: ''
                                            }
                                        }
                                    }
                                ]
                            };
                            // 使用刚指定的配置项和数据显示图表。
                            chart.setOption(option);
                        }else{
                            option = {
                                title: {
                                    text: query.sort,
                                    subtext: 'AAA',
                                    x: 'center'
                                },
                                tooltip : {
                                    trigger: 'axis',
                                    axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                                        type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                                    }
                                },
                                grid: {
                                    left: '3%',
                                    right: '4%',
                                    bottom: '3%',
                                    containLabel: true
                                },
                                xAxis : [
                                    {
                                        type : 'category',
                                        data : response.data.pb,
                                        axisTick: {
                                            alignWithLabel: true
                                        }
                                    }
                                ],
                                yAxis : [
                                    {
                                        type : 'value'
                                    }
                                ],
                                series : [
                                    {
                                        name:query.sort,
                                        type:'bar',
                                        barWidth: '60%',
                                        data:response.data.pa,
                                    }
                                ]
                            };
                            // 使用刚指定的配置项和数据显示图表。
                            chart.setOption(option);
                        }
                    }).catch(function (error) {
                        return false;
                    });
                }else{
                    var url = "doStat";
                    axios.post(url, query).then(function (response) {
                        if(JSON.stringify(response.data)=="[]"){
                            option = {
                                title: {
                                    text: '暂无统计数据',
                                    x: 'center'
                                },
                                tooltip: {
                                    trigger: 'item',
                                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                                },
                                legend: {
                                    orient: 'vertical',
                                    left: 'left',
                                    data: '',
                                },
                                series: [
                                    {
                                        name: '',
                                        type: 'pie',
                                        radius: '55%',
                                        center: ['50%', '60%'],
                                        data: '',
                                        itemStyle: {
                                            emphasis: {
                                                shadowBlur: 10,
                                                shadowOffsetX: 0,
                                                shadowColor: ''
                                            }
                                        }
                                    }
                                ]
                            };
                            // 使用刚指定的配置项和数据显示图表。
                            chart.setOption(option);
                        }else{
                            option = {
                                title: {
                                    text: query.sort,
                                    subtext: 'AAA',
                                    x: 'center'
                                },
                                tooltip: {
                                    trigger: 'item',
                                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                                },
                                legend: {
                                    orient: 'vertical',
                                    left: 'left',
                                    data: response.data,
                                },
                                series: [
                                    {
                                        name: query.sort,
                                        type: 'pie',
                                        radius: '55%',
                                        center: ['50%', '60%'],
                                        data: response.data,
                                        itemStyle: {
                                            emphasis: {
                                                shadowBlur: 10,
                                                shadowOffsetX: 0,
                                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                                            }
                                        }
                                    }
                                ]
                            };
                            // 使用刚指定的配置项和数据显示图表。
                            chart.setOption(option);
                        }
                    }).catch(function (error) {
                        return false;
                    });
                }
            },
        },
    })
</script>
</body>
</html>